# -*- coding: utf-8 -*-
# @File: crontab.py
# @Author: Liccsu
# @Time: 12/8/2022 下午10:12
# @Project: eschool-health

from apscheduler.triggers.cron import CronTrigger


class CronTriggerPlus(CronTrigger):
    @classmethod
    def plus_from_crontab(cls, expr, timezone=None):
        """
        Create a :class:`~CronTrigger` from a standard crontab expression.
        See https://en.wikipedia.org/wiki/Cron for more information on the format accepted here.

        :param expr: second, minute, hour, day of month, month, day of week, year
        :param datetime.tzinfo|str timezone: time zone to use for the date/time calculations (defaults to scheduler timezone)
        :return: a :class:`~CronTrigger` instance
        """
        values = expr.split()
        if len(values) != 7:
            raise ValueError(f'Wrong number of fields; got {len(values)}, expected 7')

        return cls(second=values[0], minute=values[1], hour=values[2], day=values[3], month=values[4],
                   day_of_week=values[5], year=values[6], timezone=timezone)
